package com.jianyushe.jianyushebaseadmin.controller;

import com.jianyushe.jianyushebaseadmin.entity.Userentity;
import com.jianyushe.jianyushebaseadmin.feign.gatewayfeign;
import com.jianyushe.jianyushebaseadmin.mapper.UserentityMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Create by Alvin
 * @Description TODO
 * @date 2022-02-14 19:00
 */
@RestController
@RequestMapping("/admin/")
@RefreshScope
// 一定要加tags不然没有效果
@Api(tags = "hello控制器类")
public class TestController {

    @Autowired
    private UserentityMapper userMapper;

    @Value("${config.test}")
    private String testV;

    @Autowired
    private gatewayfeign gatewayfeign;

    @Value("${spring.datasource.url}")
    private String url;

    @Autowired
    private DataSource dataSource;

    @ApiOperation("hellotest 方法")
    @GetMapping("test")
    public String test(@ApiParam("用户名") String name, Integer dfd){
        gatewayfeign.test();
        return "hello";
    }

    @GetMapping("data")
    public String testD() throws SQLException {
        System.out.println("配置中心：" + url);
        System.out.println(testV);
        System.out.println(dataSource.getConnection().toString());
        System.out.println(("----- selectAll method test ------"));
        List<Userentity> userList = userMapper.selectList(null);
        for (Userentity user : userList) {
            System.out.println(user);
        }
        return userList.toString();
    }
}
